/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.controller;

import com.xy.biz.fd.domain.converter.DocumentHistoryConverter;
import com.xy.biz.fd.domain.query.DocumentHistoryQuery;
import com.xy.biz.fd.domain.req.documentFavorite.GetDocumentFavoriteRequest;
import com.xy.biz.fd.domain.req.documentHistory.GetDocumentHistoryRequest;
import com.xy.biz.fd.domain.req.documentHistory.ListDocumentHistoryRequest;
import com.xy.biz.fd.domain.resp.GetDocumentHistoryResponse;
import com.xy.biz.fd.service.DocumentHistoryService;
import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.util.CalendarUtils;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 *
 *
 * @author wcs
 * @date 2021-2-3
 */
@Api(tags = "最近访问服务")
@Slf4j
@RestController
@RequestMapping("/api/fd/document_history")
public class DocumentHistoryController {

	@Autowired
	private DocumentHistoryService documentHistoryService;

	@ApiOperation(value = "文档历史删除")
	@Validatable
	@PostMapping(value = "/delete")
	public Result<?> deleteDocumentHistory(@RequestBody GetDocumentHistoryRequest request) {
		documentHistoryService.deleteDocumentHistory(request.getDocumentHistoryId());
		return Result.success();
	}

	@PostMapping(value = "/page")
	public Result<Page<GetDocumentHistoryResponse>> pageDocumentHistory(@RequestBody ListDocumentHistoryRequest request) {
		DocumentHistoryQuery query = DocumentHistoryConverter.toQuery(request);
		List<GetDocumentHistoryResponse> list = DocumentHistoryConverter.toResponse(documentHistoryService.listDocumentHistory(query));
		int count = documentHistoryService.countDocumentHistory(query);
		return Result.success(new Page<>(list, count));
	}
}
